package com.GraduationDesign.backend.controller.codeReview;

import com.GraduationDesign.backend.bl.codeReview.ReviewService;
import com.GraduationDesign.backend.blImpl.codeReview.ReviewServiceImpl;
import com.GraduationDesign.backend.po.Review;
import com.GraduationDesign.backend.po.Reviewer;
import com.GraduationDesign.backend.vo.ResponseVO;
import com.GraduationDesign.backend.vo.ReviewCommentVO;
import com.GraduationDesign.backend.vo.ReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author: wzx
 * @date: 2022/2/13
 */
@RestController
@RequestMapping("/api/code_review")
public class CodeReviewController {

    @Autowired
    ReviewService reviewService;

    @PostMapping("/add_review")
    public ResponseVO addReview(@RequestBody ReviewVO reviewVO){
        Date getDate= Calendar.getInstance().getTime();
        String dateStr=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(getDate);
        reviewVO.setCreateTime(dateStr);
        return reviewService.addReview(reviewVO);
    }

    @PostMapping("/delete_review")
    public ResponseVO deleteReview(@RequestParam Integer reviewId){
        return  reviewService.deleteReview(reviewId);
    }
    @GetMapping("/get_review_list")
    public ResponseVO getReviewList(@RequestParam("userId") Integer userId){
        return  ResponseVO.buildSuccess(reviewService.getReviews(userId));
    }
    @GetMapping("/get_reviewer_list")
    public ResponseVO getReviewerList(){
        return ResponseVO.buildSuccess(reviewService.getReviewerList());
    }

    @GetMapping("/get_recent_reviews")
    public ResponseVO getRecentReviews(@RequestParam("userId") Integer userId){
        return ResponseVO.buildSuccess(reviewService.recentReviews(userId));
    }
    @PostMapping("/add_review_content")
    public ResponseVO addReviewContent(@RequestBody ReviewCommentVO reviewCommentVO){
        return reviewService.addReviewContent(reviewCommentVO);
    }
    @GetMapping("/program_id")
    public ResponseVO getReviewListByProgramId(@RequestParam("programId") Integer programId){
        return ResponseVO.buildSuccess(reviewService.getReviewListByProgramId(programId));
    }
    @PostMapping("/confirm_group")
    public  ResponseVO confirmGroup(@RequestParam("reviewId") Integer reviewId){
        return reviewService.confirmGroup(reviewId);
    }
}
